package org.example.fastJsonEnumSerializer;

import com.alibaba.fastjson2.writer.ObjectWriter;

import java.lang.reflect.Type;

public class EnumSerializer implements ObjectWriter<BaseEnum<?>> {
    @Override
    public void write(
            com.alibaba.fastjson2.JSONWriter jsonWriter,
            Object object,
            Object fieldName,
            Type fieldType,
            long features) {

        if (object == null) {
            jsonWriter.writeNull();
            return;
        }

        BaseEnum<?> enumValue = (BaseEnum<?>) object;
        jsonWriter.writeAny(enumValue.getValue());
    }
}
